package com.example.project;

import java.io.IOException;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class SearchView extends ActionBarActivity{
	
	
		protected EditText Etext=null;
		protected ImageButton button=null;
		protected ListView list=null;
		
		
		public String [] listData=null;
		public ArrayAdapter<String> adapter=null;
		
		public MySqlite Db=null; 
	
	 	@Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.search_view);
	        Etext=(EditText)findViewById(R.id.editText1);
	        button=(ImageButton)findViewById(R.id.imageButton1);
	        list=(ListView)findViewById(R.id.searchList);
	        
	        Db=new MySqlite(this);
	    	try {
				Db.createDataBase();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	
			listData=Db.getMylist();
			
	 		adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listData);
	    	list.setAdapter(adapter);
	       
	        
	        list.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
						long arg3) {
					// TODO Auto-generated method stub
					Intent intent=new Intent(SearchView.this,PageView.class);
					intent.putExtra("file", listData[arg2]);
					startActivity(intent);				
				}
	    		
	    	});
	        button.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					if(arg0==button)
					{
						String key=Etext.getText().toString();
						if(key.length()!=0){
							Intent SP=new Intent(SearchView.this,SearchList.class);
							SP.putExtra("key",key);
							startActivity(SP); 
						}
					}
					
				}
	        	
	        });	        
	 }

}
